package Test0813;
import java.util.Scanner;

public class Test{
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 定义评委人数为4
        double[] scores = new double[4];
        double sum = 0;

        System.out.println("请输入4位评委的打分：");

        // 循环输入每位评委的分数
        for (int i = 0; i < 4; i++) {
            System.out.print("评委" + (i + 1) + "的分数：");
            scores[i] = scanner.nextDouble();

            // 验证分数是否合法（0-100分）
            if (scores[i] < 0 || scores[i] > 100) {
                System.out.println("分数必须在0-100之间，请重新输入！");
                i--; // 重新输入当前评委的分数
                continue;
            }

            sum += scores[i];
        }

        // 找出最高分和最低分
        double maxScore = scores[0];
        double minScore = scores[0];

        for (int i = 1; i < 4; i++) {
            if (scores[i] > maxScore) {
                maxScore = scores[i];
            }
            if (scores[i] < minScore) {
                minScore = scores[i];
            }
        }

        // 去掉最高分和最低分后计算平均分
        double average = (sum - maxScore - minScore) / 2;

        // 输出结果
        System.out.println("\n各位评委的打分为：");
        for (int i = 0; i < 4; i++) {
            System.out.printf("评委%d: %.1f分\n", (i + 1), scores[i]);
        }

        System.out.printf("\n最高分: %.1f分", maxScore);
        System.out.printf("\n最低分: %.1f分", minScore);
        System.out.printf("\n最终平均分(去掉最高最低分): %.2f分\n", average);

        scanner.close();
    }
}